<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	$id = getRequest('id');
	if(isset($_POST['edit_content'])){
		$dir = "../../zjx/Runtime/Cache/selectModel/"; //缓存路径
			if(empty($id)){
				$imagename = date('YmdHis').'.jpg'; //图片名称
				$upd['p_name'] = getRequest('name');
				$upd['p_info'] = addslashes(sy2dy($_REQUEST['product']));
				if($upd['p_info'] == '<br />'){
					jstop('内容不能为空');
				}
				if(!uploadFlie('image','../../../www/static/images/product/'.$imagename)){
					$imagename = '';
				}
				$upd['p_code'] = getRequest('code');
				$upd['p_image'] = $imagename;
				$upd['p_time'] = date('Y-m-d H:i:s');
				$upd['p_user'] = $_SESSION['username'];
				$upd['p_mid'] = getRequest('mid');
				$upd['p_isshow'] = getRequest('isshow');
				$tablename = 'zjx_product';
				if(Module_Edit::insert($tablename,$upd)){
					Cache_Filecache::delFileCache($dir);
					jstop('添加成功');
				}
				jstop('系统繁忙，请重试');
			}else{
				$imagename = getRequest('imagepath'); //图片名称
				$upd['p_name'] = getRequest('name');
				$upd['p_info'] = addslashes(sy2dy($_REQUEST['product']));
				if($upd['p_info'] == '<br />'){
					jstop('内容不能为空');
				}
				$upd['p_isshow'] = getRequest('isshow');
				$upd['p_code'] = getRequest('code');
				$upd['p_time'] = date('Y-m-d H:i:s');
				$upd['p_user'] = $_SESSION['username'];
				$tablename = 'zjx_product';
				if(Module_Edit::update($tablename,$upd,'p_id='.$id)){
					uploadFlie('image','../../../www/static/images/product/'.$imagename);
					Cache_Filecache::delFileCache($dir);
					jstop('修改成功');
				}
				jstop('系统繁忙，请重试');
			}
	}
	
	$allProductMod = Module_Select::getContentModInfoByUrl('product');
	if(!empty($id)){
		$productinfo = Module_Select::getProductInfoById($id);
	}
	
//	var_dump($articleinfo);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发布新产品</title>
<link rel="stylesheet" type='text/css' href='../Public/static/css/admincp/admincp.css'>
</head>
<body>
<form action="" method="post"  enctype="MULTIPART/FORM-DATA" >
<input type="hidden" name="id" value="<?php echo $id?>" />
<table width="93%" class="tb tb2 " id="tips">
	<tbody>
		<tr>
			<th class="partition" colspan='3'>技巧提示</th>
		</tr>
		<tr>
			<td class="tipsblock" colspan='3'>
				<ul id="tipslis">
					<li>请先选择相应的模块，然后再添加产品信息</li>
					<li>文本框中的内容如果是复制进来的，最好先清除所有格式之后再进行编辑</li>
					<li>产品先可以先上传照片,照片严格为<span class='red'>jpg</span>后缀，且大小不能大于1M</li>
				</ul>			
			</td>
		</tr>
	</tbody>
	<tr height="30">
		<td colspan='11'></td>
	</tr>
	<tbody>
	<?php if(empty($id)){?>
		<tr>
		  <td width="275" align="left" colspan='3'>产品所属模块：
            <select name='mid'>
              <?php 
					foreach ($allProductMod as $v){
				
				?>
              <option value="<?php echo $v['z_id']?>"
					<?php if($v['z_id'] == $_POST['id'])echo ' selected '?>><?php echo $v['z_name']?></option>
              <?php }?>
            </select></td>
		</tr>
		<?php }else{
			echo "<input type='hidden' name='imagepath' value='".$productinfo ['p_image'].'\' />';
		}?>
		<tr>
		  <td align="left">产品名称：
	      <input type='text' name='name' value='<?php echo $productinfo ['p_name']?>' size="30" /></td>
	      <td width="825" rowspan="3" align="left">
			<img alt="产品图片" src="/www/static/images/product/<?php echo $productinfo ['p_image']?>" id='uploadfile' width="110" height="" >
		 </td>
		</tr>
		<tr>
		  <td align="left">产品型号：
	      <input type='text' name='code' value='<?php echo $productinfo['p_code']?>' size="30" /></td>
		</tr>
		<tr>
			<td align="left">产品图片：
				<input type='file' name='image'/>
			</td>
		</tr>
		<tr>
			<td align="left">是否推荐：
				<input type='radio' <?php if(!$id) echo ' checked '?> name='isshow' value='0'/>不推荐&nbsp;
				<input type='radio' <?php if($productinfo['p_isshow'] == 1)echo ' checked '?> name='isshow' value='1'/>推荐
			</td>
		</tr>
		<tr>
			<td valign="top" align="left" colspan='11'>基本信息：<br>
			<INPUT id=content style="DISPLAY: none" type=hidden name="product"
				value="<?php echo htmlspecialchars($productinfo['p_info'])?>"> <INPUT
				id=content___Config style="DISPLAY: none" type=hidden> <IFRAME
				id=content___Frame
				src="../Public/static/FCK/editor/fckeditor.html?InstanceName=product&Toolbar=Default"
				frameBorder=0 width=70% scrolling=no height=400> </IFRAME></td>
		</tr>
		<tr>
			<td colspan='11'>
				<input type='submit' class="btn" name='edit_content' value="保存" />
				<input type='button' class="btn" onclick="history.back();" value="返回" />
			</td>
		</tr>
	</tbody>
</table>
</form>
</body>
</html>
<script src="/www/static/js/jquery.js" type='text/javascript'></script>
<script type="text/javascript">
$('input[name="edit_content"]').click(function(){
	if($('input#up_file').val() !='' && $('input#up_file').val().search('jpg') == -1){
		alert('图片格式必须 为jpg')
		return false;
	}
})
</script>